package com.atguigu.blog.service.impl;

import com.atguigu.blog.mapper.UserMapper;
import com.atguigu.blog.pojo.User;
import com.atguigu.blog.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.Map;

/**
 * @author MikeCoder
 * @create 2023-11-2516:40
 * @description:
 * @verson:
 */
@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    @Override
    @Transactional(readOnly = true)
    public Map<String, Object> login(User user) {
        Map<String, Object> map = null;
        User userByName = userMapper.selectUserByName(user.getUsername());
        if (userByName != null) {
            if (userByName.getPassword().equals(user.getPassword())) {
                map = new HashMap<>();
                map.put("uid", userByName.getUid());
                map.put("username", userByName.getUsername());
            }
        }
        return map;
    }

    @Override
    public User getUserByUid(Long uid) {
        return userMapper.selectUserByUid(uid);
    }

    @Override
    public Integer change(User user) {
        return userMapper.update(user);
    }
}
